#ifndef CAMERA_H
#define CAMERA_H
#include<QDebug>
#include <QOpenGLShader>


enum CameraMovement {
  FORWARD,
  BACKWARD,
  LEFT,
  RIGHT,
  UP,
  DOWN
};


class Camera {
public:
    Camera(QVector3D position = {0,0,0}, int width = 300, int height=300){
        this->cameraPos = position;
        this->lastX = width/2;
        this->lastY = height/2;

        this->UpdateCameraLookatMatVectors();
    }

 public:
    QMatrix4x4 getViewMat();
    void DealMouseMovement(GLfloat Xoffset, GLfloat Yoffset);
    void DealMouseScroll(GLfloat Yoffset);
    void DealKeyboardInputs(); // 渲染时调用
    void DealKeyInput(CameraMovement direction); // 键盘处理事件函数，单个

    void UpdateCameraLookatMatVectors();// 更新相机坐标系

public:
    // 相机相关
    QVector3D cameraPos={0,0,0};
    QVector3D cameraTarget={0,0,1};
    QVector3D cameraDirection = cameraPos-cameraTarget; // 相机朝向，与Z轴相反
    QVector3D cameraUp = {0,1,0};
    QVector3D cameraRight = QVector3D::crossProduct(cameraDirection, cameraUp);

    // 鼠标相关
    GLfloat sensitivity = 0.01f; // 鼠标灵敏度
    GLfloat movementSpeed = 0.1f; // 键盘移动速度
    GLfloat zoom = 45.0f; // 投影矩阵角度
    // 欧拉角
    GLfloat yaw = -90.0f;
    GLfloat pitch = 0.0f;
    // cameraDirection.setX(cos(yaw)*cos(pitch));
    // cameraDirection.setY(sin(pitch));
    // cameraDirection.setZ(sin(yaw)*cos(pitch));
    GLboolean isFirstMouse = GL_TRUE;
    GLboolean isLeftMousePress = GL_FALSE;

    // 屏幕坐标，上一次的位置
    int lastX,  lastY;

    // 键盘多键触控所需
    GLboolean keys[1<<10] = {0};

};


#endif // CAMERA_H
